//    Copyright (C) Kherty.  All rights reserved.
using System.Collections.Generic;
using OpenLS.Core.Serialization;
using OpenLS.Vml.Serialization;

namespace OpenLS.Vml.Drawing
{
    class RelationTable: IOfficeXmlSerializable
    {
        private readonly List<Relation> _relations = new List<Relation>();
        private Ext? _ext;

        public void ReadXml(ReadContext context)
        {
            using (var c = context.Read("relationtable"))
            {
                _ext = c.GetOptionalEnum<Ext>(VmlConstants.VmlNamespace+"ext");
                _relations.Clear();
                _relations.AddRange(c.ReadOptionalWhile<Relation>(Relation.xmlName));

            }
        }

        public void WriteXml(WriteContext context)
        {
            using (var c = context.Write("relationtable"))
            {
                c.SetOptionalEnum<Ext>(VmlConstants.VmlNamespace + "ext", _ext);
                c.WriteElements(_relations);

            }
        }
    }
}
